package game.entities {
	import org.axgl.Ax;
	import org.axgl.AxEntity;
	import org.axgl.AxSprite;
	import org.axgl.input.AxKey;
	
	/**
	 * ...
	 * @author Pierre Chamberlain
	 */
	public class Player extends AxSprite {
		private var _isInWater:Boolean;
		
		public function Player(x:Number, y:Number, graphic:Class=null, frameWidth:uint=0, frameHeight:uint=0) {
			super(x, y, graphic, frameWidth, frameHeight);
			
			//Creates a White block graphic (placeholder for now)
			create(8, 8, 0xffffffff);
			
			//Make the default camera follow this object:
			Ax.camera.follow(this);
			
			acceleration.y =	1000;
			maxVelocity.x = 	100;
			maxVelocity.y =		500;
			
			//Prevent the Player to go outside the camera's bounds
			worldBounds =		Ax.camera.bounds;
		}
		
		public override function update():void {
			super.update();
			
			if (Ax.keys.down(AxKey.LEFT)) {
				acceleration.x = -500;
			} else if (Ax.keys.down(AxKey.RIGHT)) {
				acceleration.x = 500;
			} else {
				acceleration.x = 0;
				velocity.x *= .5;
			}
			
			if (Ax.keys.pressed(AxKey.UP)) {
				if (isOnGround || isInWater) {
					y-=5;
					velocity.y = -600;
				}
			}
		}
		
		public function get isOnGround():Boolean {
			return wasTouching(AxEntity.DOWN);
		}
		
		public function get isInWater():Boolean { return _isInWater; }
		public function set isInWater(value:Boolean):void {
			_isInWater = value;
			
			maxVelocity.y =		_isInWater ? 50 : 500;
			acceleration.y =	_isInWater ? 50 : 1000;
		}
		
	}

}